package com.hmy.infrastructure.service.corpsearch.impl;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.google.gson.Gson;
import com.hmy.infrastructure.api.bo.request.corpsearch.CorpDetailSearchRequest;
import com.hmy.infrastructure.api.bo.request.corpsearch.CorpSearchRequest;
import com.hmy.infrastructure.api.bo.response.corpsearch.CorpDetailClientResponse;
import com.hmy.infrastructure.api.bo.response.corpsearch.CorpSearchResponse;
import com.hmy.infrastructure.service.corpsearch.ICorpSearchService;
import com.hmy.infrastructure.service.dto.qichacha.QichachaCorpBasicDetailDto;
import org.springframework.stereotype.Service;

/**
 * @Description 企业信息查询，企查查提供商实现类
 * @Author seven.qi
 * @Date 2023/11/27 10:39
 * @Version 1.0
 */
@Service("qichachaCorpSearchService")
public class QichachaCorpSearchService extends QichachaCorpSearchBaseService implements ICorpSearchService {

    private static final String name_search_uri = "/NameSearch/GetList";

    @Override
    public CorpSearchResponse nameSearch(CorpSearchRequest corpSearchRequest) throws Exception {
        String result = nameSearch(name_search_uri, BeanUtil.beanToMap(corpSearchRequest));
        Gson gson = new Gson();
        return gson.fromJson(JSONUtil.parseObj(result).get("Result").toString(), CorpSearchResponse.class);
    }

    @Override
    public CorpDetailClientResponse detailSearch(CorpDetailSearchRequest detailSearchRequest) throws Exception {
        QichachaCorpBasicDetailDto qichachaCorpBasicDetailDto = basicDetailsByName(BeanUtil.beanToMap(detailSearchRequest));
        return BeanUtil.copyProperties(qichachaCorpBasicDetailDto, CorpDetailClientResponse.class);
    }
}
